<?php

namespace zhtfrontend\models\datas;

use common\models\datas\IsuserInfo;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\helpers\ArrayHelper;
use doumiaoduo\ueditor\ImageUploadMultipleTrait2;

/**
 * This is the model class for table "{{%commission_settlement}}".
 *
 * @property integer $id
 * @property integer $salesman_id
 * @property integer $status
 * @property string $settlement_amount
 * @property string $commission_money
 * @property string $payment_method
 * @property integer $payment_id
 * @property string $operator
 * @property integer $operator_id
 * @property integer $created_at
 * @property string $voucher_url
 * @property integer $created_at_settlement
 * @property integer $payment_finance_id
 * @property integer $payment_finance_name
 */
class CommissionSettlement extends \zhtfrontend\components\bases\BaseModel
{
    use ImageUploadMultipleTrait2;
    public $picture;
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%commission_settlement}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['salesman_id', 'status', 'payment_id', 'operator_id', 'created_at'], 'integer'],
            [['settlement_amount', 'commission_money'], 'number'],
            [['payment_method'], 'string', 'max' => 20],
            [['operator'], 'string', 'max' => 50],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('zhtfrontend', '自增id'),
            'salesman_id' => Yii::t('zhtfrontend', '发卡人id'),
            'status' => Yii::t('zhtfrontend', '付款状态'),
            'settlement_amount' => Yii::t('zhtfrontend', '需结算金额'),
            'commission_money' => Yii::t('zhtfrontend', '佣金'),
            'payment_method' => Yii::t('zhtfrontend', '付款方式'),
            'payment_id' => Yii::t('zhtfrontend', '付款方式'),
            'operator' => Yii::t('zhtfrontend', '操作人'),
            'operator_id' => Yii::t('zhtfrontend', '操作人id'),
            'created_at' => Yii::t('zhtfrontend', '创建时间'),
            'pic_url' => Yii::t('zhtfrontend', '上传凭证'),
            'created_at_settlement' => Yii::t('zhtfrontend', '付款时间'),
            'payment_finance_id' => Yii::t('zhtfrontend', '付款人'),
            'payment_finance_name' => Yii::t('zhtfrontend', '付款人'),
        ];
    }
    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            [
                'class' => TimestampBehavior::className(),
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
                ],
            ],
        ]);
    }

    public function getSalesman(){
        return $this->hasOne(IsuserInfo::className(),['id'=>'salesman_id']);
    }

    public function getTeacher(){
        return $this->hasOne(Teacher::className(),['id'=>'salesman_id']);
    }

    public function getHeadmaster(){
        return $this->hasOne(Headmaster::className(),['id'=>'salesman_id']);
    }
}
